/*******************************************************************************
 * Copyright (c) 2025-08-06 @author <a href="mailto:iffiff1@gmail.com">Tyler Chen</a>.
 * All rights reserved.
 *
 * Contributors:
 *     <a href="mailto:iffiff1@gmail.com">Tyler Chen</a> - initial API and implementation.
 ******************************************************************************/
package org.iff.util.llm.qwen;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * 流式返回结果
 * <pre>
 * {
 *     "id": "chatcmpl-e30f5ae7-3063-93c4-90fe-beb5f900bd57",
 *     "choices": [
 *         {
 *             "delta": {
 *                 "content": "",
 *                 "function_call": null,
 *                 "refusal": null,
 *                 "role": "assistant",
 *                 "tool_calls": null
 *             },
 *             "finish_reason": null,
 *             "index": 0,
 *             "logprobs": null
 *         }
 *     ],
 *     "created": 1735113344,
 *     "model": "qwen-plus",
 *     "object": "chat.completion.chunk",
 *     "service_tier": null,
 *     "system_fingerprint": null,
 *     "usage": null
 * }
 * </pre>
 *
 * @author <a href="mailto:iffiff1@gmail.com">Tyler Chen</a>
 * @since 2025-08-06
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class TextChatStream {
    @JsonProperty("id")
    private String id;
    @JsonProperty("choices")
    private List<Choices> choices;
    @JsonProperty("created")
    private Long created;
    @JsonProperty("model")
    private String model;
    @JsonProperty("object")
    private String object;
    @JsonProperty("service_tier")
    private Object serviceTier;
    @JsonProperty("system_fingerprint")
    private Object systemFingerprint;
    @JsonProperty("usage")
    private Object usage;

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class Choices {
        @JsonProperty("delta")
        private Delta delta;
        @JsonProperty("finish_reason")
        private Object finishReason;
        @JsonProperty("index")
        private Long index;
        @JsonProperty("logprobs")
        private Object logprobs;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class Delta {
        @JsonProperty("content")
        private String content;
        @JsonProperty("function_call")
        private Object functionCall;
        @JsonProperty("refusal")
        private Object refusal;
        @JsonProperty("role")
        private String role;
        @JsonProperty("tool_calls")
        private List<ToolCall> toolCalls;
        @JsonProperty("reasoning_content")
        private String reasoningContent;
        @JsonProperty("audio")
        private Audio audio;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class Audio {
        @JsonProperty("transcript")
        private String transcript;
        @JsonProperty("data")
        private String data;
        @JsonProperty("expires_at")
        private Integer expires_at;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class ToolCall {
        @JsonProperty("id")
        private String id;
        @JsonProperty("type")
        private String type;
        @JsonProperty("index")
        private Integer index;
        @JsonProperty("function")
        private FunctionCall functionCall;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class FunctionCall {
        @JsonProperty("arguments")
        private String arguments;
        @JsonProperty("name")
        private String name;
    }
}
